home *** CD-ROM | disk | FTP | other *** search
Text File | 1988-09-27 | 6.4 KB | 360 lines | [TEXT/elb ] |
-
-
- {********************************}
- {* File: Reporter.p *}
- {* *}
- {* Prints the entire *}
- {* contents of the container *}
- {* *}
- {* ------------------------ *}
- {* In: params[1] = handle *}
- {* to the text to be printed *}
- {* *}
- {* ------------------------ *}
- {* © 1988, Donald Koscheka, *}
- {* All Rights Reserved *}
- {* ------------------------ *}
- {********************************}
-
- (****************************
- BUILD SEQUENCE
-
- pascal Reporter.p
- link -m ENTRYPOINT -rt ∂
- XCMD=6555 -sn Main=Reporter ∂
- Reporter.p.o ∂
- "{Libraries}"Interface.o ∂
- "{PLibraries}"Paslib.o ∂
- -o "{xcmds}"testxcmds
-
- *****************************)
-
- {$S Reporter }
-
- UNIT Donald_Koscheka;
-
- {----INTERFACE-----}
-
- INTERFACE
-
- USES
- MemTypes, QuickDraw, OSIntf,
- ToolIntf, PackIntf, HyperXCmd,
- PrintTraps;
-
-
- PROCEDURE EntryPoint(pPtr:XCmdPtr);
-
- {-----IMPLEMENTATION-----}
-
- IMPLEMENTATION
-
- {$R-}
- CONST
- CARD = TRUE;
- BKGND = FALSE;
- NILCHAR = $00;
- CR = $0D;
- TAB = $09;
- SPACE = $20;
- FF = $0C;
- LINEFEED = $0A;
- QUOTE = $22;
- COMMA = $2C;
- PERIOD = $2E;
- PAREN = $28;
-
- TYPE
- Str31 = String[31];
-
- PROCEDURE Reporter(pPtr:XCmdPtr);FORWARD;
-
- {----EntryPoint-----}
-
- PROCEDURE EntryPoint(pPtr: XCmdPtr);
- BEGIN
- Reporter(pPtr);
- END;
-
-
- {-----Reporter-----}
-
- Function CalcNextWord(VAR wPtr:Ptr):INTEGER;
- (**********************
- * Given a pointer to a
- * word, calculate the
- * length of the next word
- * in the run. The length
- * is determined by adding
- * the width of each character
- * together until a word
- * break is hit.
- *
- * The difference between
- * tpos and wpos is always
- * one word (including the
- * sticky characters)
- *
- * IN: Pointer to text
- * wPtr == pointer to NEXT word in
- * run (or NIL if No next word)
- *
- * OUT: Width of the next
- * word in the line
- ***********************)
- VAR
- done : BOOLEAN;
- wLen : INTEGER;
- BEGIN
- done := FALSE;
- wLen := 0;
-
- WHILE NOT done DO
- BEGIN CASE wPtr^ OF
-
- CR,FF,LINEFEED,NILCHAR:
- done := TRUE;
- TAB:
- BEGIN
- WLen:=wLen+CharWidth( chr(SPACE) );
- done := TRUE;
- END;
-
- SPACE, QUOTE, COMMA, PERIOD:
- BEGIN
- wlen:=wLen+CharWidth( chr(wPtr^));
- done := TRUE;
- wPtr:=Pointer( ORD(wPtr) +1);
- END;
-
- OTHERWISE
- BEGIN
- WLen:=wLen+CharWidth( chr(wPtr^));
- wPtr := Pointer( ORD(wPtr) + 1 );
- END;
- END; {*** CASE wPtr^ OF ***}
- END; {*** WHILE NOT done ***}
-
- IF wPtr^ = 0 THEN wPtr := NIL;
-
- CalcNextWord := wLen;
- END;
-
-
- Procedure PrintHandle( hand : Handle; printer : TPPrPort; Prec : THPrint );
- (**********************
- * Print the data passed
- * as a handle and
- * using the given printer
- * port.
- *
- * Prints the data into
- * the current port and
- * handles word wrap and
- * page breaks.
- *
- **********************)
- VAR
- done : BOOLEAN;
- lineHite,
- wordSize : INTEGER;
- pageHite,
- pageWidth : INTEGER;
- num : INTEGER;
- cPos : Ptr;
- wPos : Ptr;
- tPos : Ptr;
- lineRect : Rect;
- fontInfo : FontInfo;
-
- PROCEDURE EjectPage;
- (****************************
- * Eject the current page and
- * adjust the rectangle
- * accordingly
- *
- ****************************)
- BEGIN
- PrClosePage( printer );
- PrOpenPage( printer, NIL );
-
- {*** Opening a new page yields ***}
- {*** a new grafport, reset it ***}
- TextFont( GENEVA );
- TextSize( 9 );
- GetFontInfo( FontInfo );
- lineHite := fontInfo.ascent +
- fontInfo.descent +
- fontInfo.leading;
-
- WITH Prec^^.prInfo.rpage DO
- BEGIN
- lineRect.Top := top;
- lineRect.Bottom:=lineRect.top +lineHite;
- lineRect.Right := lineRect.left;
- Moveto(lineRect.left,
- lineRect.bottom );
- END;
- tpos := Pointer( ORD( tpos ) + 1 );
- END;
-
-
- PROCEDURE NewLine;
- (******************************
- * Move to a new position on the
- * page.
- ******************************)
- BEGIN
- WITH lineRect DO
- BEGIN
- top := top + lineHite;
- bottom := bottom + lineHite;
- MoveTo( left, bottom );
-
- IF bottom > pageHite THEN
- EjectPage;
-
- Right := Prec^^.prInfo.rpage.left;
- END;
- END;
-
- PROCEDURE DrawLine;
- (******************************
- * Draw the current line please
- ******************************)
- BEGIN
- DrawText( cPos, 0, num );
- lineRect.Right := lineRect.left + wordSize;
- tpos := Pointer( ORD( tpos ) + 1 ); { debug }
- num := INTEGER( ORD(tPos) - ORD(wPos) );
- cPos := wPos;
- wPos := tPos;
- END;
-
-
- {----- Reporter -----}
- BEGIN
- TextFont( GENEVA );
- TextSize( 9 );
- GetFontInfo( FontInfo );
- lineHite := fontInfo.ascent +
- fontInfo.descent +
- fontInfo.leading;
-
- {*** get information about page ***}
- WITH Prec^^.prInfo.rpage DO
- BEGIN
- pageHite := bottom - top;
- pageWidth := right-left;
- lineRect.top := top;
- lineRect.bottom:= top + lineHite;
- lineRect.left := left;
- lineRect.right := left;
- MoveTo( lineRect.left, lineRect.bottom );
- END;
-
- Hlock( hand );
- cPos := hand^;
- wPos := cPos;
- num := 0;
- done := false;
-
- REPEAT
- tPos := wPos;
-
- CASE tPos^ OF
- LINEFEED, CR:
- BEGIN
- DrawLine;
- NewLine;
- wpos := tpos;
- END;
-
- FF:
- BEGIN
- EjectPage;
- wpos := tpos;
- lineRect.right := lineRect.right + wordSize;
- END;
-
- NILCHAR:
- BEGIN
- DrawLine;
- done := TRUE;
- END;
-
- OTHERWISE
- BEGIN
- wordSize := CalcNextWord( tPos );
- IF( wordSize + lineRect.right ) < pageWidth THEN
- BEGIN
- num := num + INTEGER( ORD(tPos) - ORD(wPos) );
- wPos := tPos;
- END
- ELSE
- BEGIN
- DrawLine;
- NewLine;
- END;
- lineRect.right:=lineRect.right + wordSize;
- END;
-
- END {** CASE ***};
- UNTIL done;
-
- PRClosePage( printer );
- HUnlock( hand );
- END;
-
-
-
- PROCEDURE Reporter(pPtr: XCmdPtr);
- (*********************
- * Print the data that's
- * passed in as a
- * parameter.
- **********************)
- VAR
- fieldPtr : Ptr;
- fieldName : Str255;
- fieldType : BOOLEAN;
- fieldData : Handle;
- prRecHandle : THPrint;
- prPort : TPPrPort;
- myStRec : TPrStatus;
-
- {$I XCmdGlue.inc }
-
- BEGIN
- WITH pPtr^ DO
- IF (paramCount <> 0) AND
- (params[1] <> NIL) THEN
- BEGIN
-
- PROpen;
- prRecHandle := THPrint(NewHandle( SIZEOF(TPRINT) ));
- PrintDefault( prRecHandle );
-
- IF PRJobDialog( prRecHandle ) THEN BEGIN
- prPort := PROpenDoc( prRecHandle, NIL, NIL );
- PrOpenPage( prPort, NIL );
-
- PrintHandle( params[1], prPort, prRecHandle );
-
- PrCloseDoc( prPort );
-
- IF(prRecHandle^^.prJob.bJDocLoop = bSpoolLoop) AND (PrError = noErr) THEN
- PRPicFile( prRecHandle, NIL, NIL, NIL, myStRec );
-
- END; {*** IF PRJobDialog ***}
-
- DisposHandle(Handle(prRecHandle) );
- PrClose;
-
- END; {*** paramCount <> 0 ***}
- pPtr^.returnValue := NIL;
- END; {*** PROCEDURE Reporter ***}
-
- END.
-
-